package personnal.blog2pdf.data;

public class PostError {

    private Integer postId;

    private Throwable cause;

    public PostError(Integer id, Throwable exception) {
        super();
        this.postId = id;
        if (exception != null) {
            Throwable nestedCause = exception;
            while (nestedCause.getCause() != null) {
                nestedCause = nestedCause.getCause();
            }
            this.cause = nestedCause;
        }
    }

    public Integer getPostId() {
        return this.postId;
    }

    public Throwable getCause() {
        return this.cause;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(this.postId).append(';');
        if (this.cause != null) {
            builder.append(this.cause.getClass().getName()).append(';');
            builder.append(this.cause.getMessage()).append(';');
        } else {
            builder.append("No exception type;");
            builder.append("No exception message;");
        }
        return builder.toString();

    }
}
